import eslintPlugin from "vite-plugin-eslint";

const path = require('path');
import {defineConfig, loadEnv} from 'vite';
import vue from '@vitejs/plugin-vue';
import {createHtmlPlugin} from "vite-plugin-html";
import vueJsx from "@vitejs/plugin-vue-jsx";

const getViteEnv = (mode) => {
    // eslint-disable-next-line no-undef
    return loadEnv(mode, process.cwd());
};

export default defineConfig(({mode}) => {
    let devAlias = [];
    let viteEnv = getViteEnv(mode);
    return {
        plugins: [vue(), vueJsx(),
            //     eslintPlugin({
            //     include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
            // }
            // ),
            createHtmlPlugin({
                minify: true,
                inject: {
                    data: {
                        ...viteEnv,
                    }
                }
            })],
        resolve: {
            // extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
            alias: [
                ...devAlias,
                {find: "@", replacement: path.resolve("./src")}
            ],
        },
        server: {
            port: 3333,
            proxy: {
                '/api': {
                    secure: false,
                    target: viteEnv.VITE_APP_API_BASEURL,
                    ws: true,
                    rewrite: (path) => path.replace(/^\/api/, "")
                }
            }
        }
    }
});
